import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    goodList: [
      {
        name: '诸葛亮',
        price: 1000,
        num: 1,
        checked: false
      },
      {
        name: '蔡文姬',
        price: 1500,
        num: 1,
        checked: false
      },
      {
        name: '妲己',
        price: 2000,
        num: 1,
        checked: false
      },
      {
        name: '鲁班',
        price: 2200,
        num: 1,
        checked: false
      }
    ]
  },
  getters: {},
  mutations: {
    addFn (state, index) {
      console.log(index)
      state.goodList[index].num = state.goodList[index].num + 1
    },
    subFn (state, index) {
      state.goodList[index].num > 0
        ? state.goodList[index].num--
        : (state.goodList[index].num = 0)
    },
    delFn (state, index) {
      state.goodList.splice(index, 1)
    }
  },
  actions: {},
  modules: {}
})
